/* watrayucprojectdialog.vala
 *
 * Copyright (C) 2009  Matias De la Puente
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.

 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.

 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
 *
 * Author:
 * 	Matias De la Puente <mfpuente.ar@gmail.com>
 */
using Gtk;

public class WatrayUC.ProjectDialog : Dialog
{
	private Project _project;
	private Entry _prj_name = new Entry ();
	private Entry _prj_description = new Entry ();
	private Entry _prj_ucontroller = new Entry ();
	private Entry _prj_author = new Entry ();
	
	public ProjectDialog (string title, Project project)
	{
		_project = project;
		this.title = title;
		this.response += on_response;
		
		if (_project.name!="")
		{
			_prj_name.text = _project.name;
			_prj_description.text = _project.description;
			_prj_ucontroller.text = _project.ucontroller;
			_prj_author.text = _project.author;
		}
		
		var size_group = new SizeGroup (SizeGroupMode.HORIZONTAL);
		
		this.border_width = 5;
		this.has_separator = false;
		this.vbox.spacing = 5;
		
		var label = new Label("<b>" + _("Project") + "</b>");
		label.use_markup = true;
		label.xalign = 0;
		this.vbox.pack_start (label, false, false, 0);
		
		HBox hbox;
		if (_project.name=="")
		{
			hbox = create_hbox ("\t" + _("Proyect name:"), size_group);
			hbox.pack_start_defaults (_prj_name);
		}
		hbox = create_hbox ("\t" + _("Description:"), size_group);
		hbox.pack_start_defaults (_prj_description);
		hbox = create_hbox ("\t" + _("Microcontroller:"), size_group);
		hbox.pack_start_defaults (_prj_ucontroller);
		hbox = create_hbox ("\t" + _("Author:"), size_group);
		hbox.pack_start_defaults (_prj_author);
		
		this.add_button (STOCK_OK, ResponseType.OK);
		this.add_button (STOCK_CANCEL, ResponseType.CANCEL);
		this.set_default_response (ResponseType.OK);
		this.vbox.show_all ();
	}
	
	private HBox create_hbox (string title, SizeGroup size_group)
	{
		var hbox = new HBox (false, 5);
		this.vbox.pack_start (hbox, false, false, 0);

		var label = new Label (title);
		hbox.pack_start (label, false, false, 0);
		label.xalign = 0;
		size_group.add_widget (label);

		return hbox;
	}
	
	private void on_response (ProjectDialog dialog, int response_id)
	{
		if (response_id == ResponseType.OK)
		{
			_project.name = _prj_name.text;
			_project.description = _prj_description.text;
			_project.author = _prj_author.text;
			_project.ucontroller = _prj_ucontroller.text;
		}
	}
}

